import static org.junit.Assert.*;

import java.io.IOException;
import java.util.List;

import net.narusas.aceauction.push.db.DeviceDAO;
import net.narusas.aceauction.push.db.GoodsSearchDAO;
import net.narusas.aceauction.push.model.Device;

import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class DeviceModelTestl {

	@Test
	@Ignore
	public void test() {
		FileSystemXmlApplicationContext ctxt = new FileSystemXmlApplicationContext("cfg/spring.cfg.xml");
		DeviceDAO deviceDao = (DeviceDAO) ctxt.getBean("deviceDAO");
		List<Device> devices = deviceDao.getAll();
		for (Device device : devices) {
			System.out.println(device);
		}
	}

	@Test
	public void test2() throws IOException {
		FileSystemXmlApplicationContext ctxt = new FileSystemXmlApplicationContext("cfg/spring.cfg.xml");
		GoodsSearchDAO goodsSearchDao = (GoodsSearchDAO) ctxt.getBean("goodsSearchDAO");
		assertNotNull(goodsSearchDao.getDataSource());
		String narusasToken = "af9b71a44d951eb787430072e9deabc203dca654a5b315828c724c4c14c21d7a";

		Device device = new Device();
		device.setPushToken(narusasToken);
		// //
		// device.setPushToken("af9b71a44d951eb787430072e9deabc203dca654a5b315828c724c4c14c21d7a");
		device.setType("iOS");
		device.setAreaCode(10);
		device.setAreaCode2("중계동");
		device.setAreaCode3("무지게연립");
		System.out.println(goodsSearchDao.generateSQL(device));
		
//		assertEquals(
//				"SELECT" +
//				" 	count(a.id)" +
//				"FROM" +
//				" 	aceauction.ac_goods a" +
//				"WHERE" +
//				" 	a.area_code = '10'" +
//				" 	and a.address like '%중계동%'" +
//				" 	and a.appoint_result in ('신건','유찰','재진행')" +
//				" 	and a.appoint_result_date >= now()" +
//				"ORDER BY" +
//				"	 a.appoint_result_date asc " +
//				"LIMIT" +
//				" 	0, 20",
//				goodsSearchDao.generateSQL(device).replaceAll("\n", ""));
//		
//		assertEquals(12, goodsSearchDao.badgeOf(device)); // 2012-02-11 기준

		// List<Device> devices = deviceDao.getAll();
		// for (Device device : devices) {
		// System.out.println(device);
		// }
	}
}
